package com.angzh.bolibao.controller;

import javax.servlet.http.HttpSession;

import com.angzh.bolibao.model.Commission;
import com.angzh.bolibao.model.User;
import com.jfinal.core.Controller;

public class CommissionController extends Controller{
	
	public void show(){
		int type=Integer.parseInt(getPara("type"));
		HttpSession session = getSession(true);
		User user = (User)session.getAttribute("admin");
		int companyId = user.getInt("id");
		setAttr("commission",Commission.dao.getCommission(type,companyId));
		setAttr("commission2",Commission.dao.getCommission(1,companyId));
		render("/pages/group/commission.jsp");
	}
	public void update(){
		Commission c = getModel(Commission.class);
		if(c.getInt("id")!=null&&!c.getInt("id").equals("")){
			c.update();
		}else{
			c.save();
		}
		int type=c.getInt("type");
		setAttr("msg","更改成功！");
		HttpSession session = getSession(true);
		User user = (User)session.getAttribute("admin");
		int role = user.getInt("role");
		if(role==1){
			redirect("/commission/show?type="+type);
		}else{
			redirect("/commission/companyshow?type="+type);
		}
	}
	public void companyshow(){
		int type=Integer.parseInt(getPara("type"));
		HttpSession session = getSession(true);
		User user = (User)session.getAttribute("admin");
		int companyId = user.getInt("id");
		setAttr("commission",Commission.dao.getCommission(type,companyId));
		render("/pages/company/commission.jsp");
	}
}
